import QtQuick 1.0
import com.nokia.meego 1.0
import "HarmattanUIConstants.js" as Constants

Rectangle {
    id: busyLabel

    property alias running: busyIndicator.running
    property alias text: informativeText.text
    property int defaultHeight: Constants.DEFAULT_BAR_HEIGHT

    /**
     * Displays the label.
     */
    function show()
    {
        console.debug("BusyLabel.qml: show()");

        if (hideTimer.running) {
            hideTimer.stop();
        }

        running = true;
        opacity = 1.0;
        height = defaultHeight;
    }

    /**
     * Hides the label.
     */
    function hide()
    {
        console.debug("BusyLabel.qml: hide()");

        if (running || opacity > 0 || height > 0) {
            hideTimer.restart();
        }
    }

    height: defaultHeight
    color: Constants.DARK_TRANSLUCENT

    Behavior on height { NumberAnimation { duration: 250 } }
    Behavior on opacity { NumberAnimation { duration: 250 } }

    Row {
        anchors {
            fill: parent
            margins: Constants.DEFAULT_MARGIN
        }

        spacing: Constants.DEFAULT_MARGIN

        BusyIndicator {
            id: busyIndicator
            y: (busyLabel.height - height) / 2
            platformStyle: BusyIndicatorStyle { size: "medium" }
            running: true
        }

        Text {
            id: informativeText
            width: busyLabel.width - busyIndicator.width - Constants.DEFAULT_MARGIN
            height: busyLabel.height
            verticalAlignment: Text.AlignVCenter
            color: Constants.DEFAULT_TEXT_COLOR
            font.pixelSize: Constants.DEFAULT_FONT_PIXEL_SIZE
        }
    }

    Timer {
        id: hideTimer
        repeat: false
        running: false
        interval: 500

        onTriggered: {
            busyLabel.height = 0;
            busyLabel.opacity = 0;
            busyLabel.running = false;
        }
    }
}

// End of file.
